#include "GetAccelReadingReply.hpp"
#include "NetUtil.hpp"

static const unsigned int PAYLOAD_SIZE = 6;

namespace kieper {
    GetAccelReadingReply::GetAccelReadingReply(uint32_t packetId, uint16_t deviceId, uint16_t accelX, uint16_t accelY,
        uint16_t accelZ) : Message(new Packet(PAYLOAD_SIZE, Packet::TYPE_DATA,
        Packet::DELIVERY_SYNC, Packet::SCOPE_DEVICE_SPECIFIC, Packet::DIRECTION_RESPONSE, 0)) {
        getPacket().setPacketId(packetId);
        getPacket().setDeviceId(deviceId);
        netutil::setAsNbo16(getPacket().getPayload(), 0, accelX);
        netutil::setAsNbo16(getPacket().getPayload(), 1, accelY);
        netutil::setAsNbo16(getPacket().getPayload(), 2, accelZ);
    }
    
    GetAccelReadingReply::GetAccelReadingReply(const IncomingPacket& packet) :
        Message(new Packet(PAYLOAD_SIZE, packet.getBuffer())) {}

    GetAccelReadingReply::~GetAccelReadingReply() {}
    
    uint16_t GetAccelReadingReply::getAccelX() {
        return netutil::getFromNbo16(getPacket().getPayload(), 0);
    }
    
    uint16_t GetAccelReadingReply::getAccelY() {
        return netutil::getFromNbo16(getPacket().getPayload(), 1);
    }

    uint16_t GetAccelReadingReply::getAccelZ() {
        return netutil::getFromNbo16(getPacket().getPayload(), 2);
    }
}
